package com.example.everying.model.entity.content;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @program: everything
 * @description: 发布文章内容
 * @author: zw
 * @create: 2025-05-14 16:45
 **/
@Data
@TableName("activity_article")
public class ActivityArticle implements Serializable {

    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @ApiModelProperty(value = "主键")
    @NotNull(message = "发表内容id不能为空")
    private String id;

    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @ApiModelProperty(value = "用户id")
    private String userId;

    @ApiModelProperty(value = "用户id")
    private String orderNo;

    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @ApiModelProperty(value = "申请人id")
    private String applyId;

    @NotNull(message = "内容不能为空")
    @Size(message = "最多700字符", max = 700)
    @ApiModelProperty(value = "内容")
    private String content;

    @Size(message = "最多700字符", max = 700)
    @ApiModelProperty(value = "富文本内容")
    private String contents;

    @NotNull(message = "标题")
    @Size(message = "最多255字符", max = 255)
    @ApiModelProperty(value = "标题")
    private String title;

    @ApiModelProperty(value = "位置")
    private String location;

    @NotNull(message = "状态不能为空")
    @ApiModelProperty(value = "公开状态：0：公开；1：私密；")
    private Integer publicStatus;

    @ApiModelProperty(value = "悬赏金")
    private BigDecimal money;

    @ApiModelProperty(value = "发布类型：0：文章；1：卖；2：买；3:广告")
    private Integer type;

    @ApiModelProperty(value = "开始时间")
    @TableField(value = "start_time")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime startTime;

    @ApiModelProperty(value = "结束时间")
    @TableField(value = "end_time")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime endTime;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "create_time")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "更新时间")
    @TableField(value = "update_time")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;

    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @ApiModelProperty(value = "修改人id")
    private String updater;

    @ApiModelProperty(value = "经纬度")
    private String latAndLon;

    @ApiModelProperty(value = "逻辑删除(1:已删除，0:未删除)")
    @TableLogic//逻辑删除
    @TableField("is_delete")
    private int isDelete;

    @ApiModelProperty(value = "浏览数量")
    private Integer views;

    @ApiModelProperty(value = "点赞数量")
    private Integer thumbs;

    @ApiModelProperty(value = "话题标签")
    private String topic;

    @ApiModelProperty(value = "人数")
    private Integer peopleNum;

    @ApiModelProperty(value = "接单类型:0:正常；1：自动接单；2：手动接单")
    private String ordersType;

    @ApiModelProperty(value = "隐私信息")
    private String information;

    @ApiModelProperty(value = "文章状态 1-进行中 2-未开始 3-已完成; 4：失效；")
    private String status;

    @ApiModelProperty(value = "文章申诉状态 0-申诉中 3-未申诉")
    private String appealStatus;

    @ApiModelProperty(value = "权重0-9")
    private Integer weight;

    @ApiModelProperty(value = "查看状态：1：已读；2：未读；")
    private Integer artViewStatus;

    @ApiModelProperty(value = "待评价状态：0-发布人删除 1-接单人删除 2-都不删除")
    private String ratingViewStatus;

    @ApiModelProperty(value = "评价已读未读(0-发布人已读 1-申请人已读 2-都已读 3-都未读)")
    private String ratingReadStatus;

    @ApiModelProperty(value = "是否评论(1:是，0:否)")
    @TableField("is_comment")
    private Integer isComment;

    @ApiModelProperty(value = "图片路径")
    @TableField("picture_url")
    private String pictureUrlStr;

    @TableField(exist = false) // 声明非数据库字段
    private List<String> pictureUrl; // 接收前端数组

    // Getter 和 Setter 需手动处理转换逻辑
    public void setPictureUrl(List<String> pictureUrl) {
        this.pictureUrl = pictureUrl;
        if (pictureUrl != null) {
            this.pictureUrlStr = String.join(",", pictureUrl);
        }
    }

    public List<String> getPictureUrl() {
        if (pictureUrlStr != null && !pictureUrlStr.isEmpty()) {
            return Arrays.asList(pictureUrlStr.split(","));
        }
        return pictureUrl;
    }
}
